#include <iostream>
#include <vector>
#include <list>
#include <algorithm>

using namespace std;

int main()
{
    int t;
    cin >> t;
    for (int i=1; i<=t; ++i)
    {
        int n, m;
        cin >> n >> m;
        vector<list<int>> edg(n+1);
        bool *vis = new bool[n+1]();
        int *deg = new int [n+1]();

        for (int j=1; j<=m; ++j)
        {
            int v1, v2;
            scanf("%d%d", &v1, &v2);
            list<int> tmp = edg[v1];
            tmp.push_back(v2);
            edg[v1].push_back(v2);
            edg[v2].push_back(v1);
            ++deg[v1]; ++deg[v2];
        }

        vector<int> ans;
        int k = 0, cnt = 0;
        for (int i=1; i<=n; ++i)
        {
            if (vis[i]==true)
                continue;
            vis[i] = true;
            ++k;
            ans.push_back(i);
            ++cnt;
            for (auto it:edg[i])
            {
                vis[it] = true;
                ++cnt;
            }
            if (cnt == n)
                break;
        }
        cout << k << endl;
        for (auto it:ans)
            printf("%d ", it);
        printf("\n");
        delete [] vis; delete [] deg;
    }
    return 0;
}
